package com.bwie.gddproject.search.precenter;

import com.bwie.gddproject.net.OnNetLitenner;
import com.bwie.gddproject.search.model.GoodsBean;
import com.bwie.gddproject.search.model.ISearchModel;
import com.bwie.gddproject.search.model.SearchModel;
import com.bwie.gddproject.search.view.ISearchActivity;

/**
 * Created by 我走路带风 on 2017/12/16.
 */

public class SearchPrecenter implements ISearchPrecenter {
    private ISearchModel searchModel;
    private ISearchActivity searchActivity;
    private String keyWords;
    public SearchPrecenter(ISearchActivity searchActivity) {
        this.searchActivity = searchActivity;
        searchModel = new SearchModel();
    }

    @Override
    public void getGoodByKeyWords() {
        keyWords = searchActivity.getKeyWords();
        searchModel.getGoods(new OnNetLitenner<GoodsBean>() {
            @Override
            public void success(GoodsBean goodsBean) {
                searchActivity.showGoods(goodsBean);
            }

            @Override
            public void fail(String errer) {
                searchActivity.toast("搜索失败!");
            }
        }, keyWords, "1");
    }
    @Override
    public void loadMore(String page){

        keyWords = searchActivity.getKeyWords();
        searchModel.getGoods(new OnNetLitenner<GoodsBean>() {
            @Override
            public void success(GoodsBean goodsBean) {

                searchActivity.loadMore(goodsBean);
            }

            @Override
            public void fail(String errer) {
                searchActivity.toast("加载失败!");
            }
        }, keyWords, page+"");
    }

}
